#include "StepByStep.h"

#ifndef DFS
#include "Queue.h"

Queue Q;

void InitQueue(Queue *Q)
{
  Q->Front = Q->Rear = NULL;
}

void AppendQueue(Queue *Q, PredKnowledge *PC)
{
  QueueStru *Pt;

  Pt = (QueueStru *) calloc(1, sizeof(QueueStru));
  Pt->PC = PC;
  if (Q->Rear == NULL) Q->Front = Q->Rear = Pt;
  else {
         Q->Rear->next = Pt;
         Q->Rear = Pt;
  }
}

void PrintQueue(Queue *Q)
{
  PredKnowledge *Pd;
  QueueStru     *Pt;

  for (Pt = Q->Front; Pt != NULL; Pt = Pt->next) {
//  fprintf(Output, "\n");  PrintPredication(12, Pt->PC, TRUE);
    Pd = Pt->PC;
    fprintf(Output, "\n %s", (Pd->Type==NOT ? "not ":""));
    PrintTypedArray(PREDNAME(Pd->PredNo), PREDNUMPARA(Pd->PredNo), Pd->Para);
  }
  fprintf(Output, "\n");
}

PredKnowledge * GetQueue(Queue *Q)
{
  PredKnowledge *Pc;
  QueueStru     *Pt;

  Pt = Q->Front;
  Pc = Pt->PC;

  Q->Front = Pt->next;  free(Pt);

  if (Q->Front == NULL) Q->Rear = NULL;

  return Pc;
}

void GenerateKnowledgeTreeBFS(int Height, PredKnowledge *Pd)
{
}

void GenerateKnowledgeTreeByBFS(int Height, PredKnowledge *Pd)
{
  PredKnowledge *PC;

  InitQueue(&Q);
  AppendQueue(&Q, Pd);

  while (Q.Front != NULL) {
    PC = GetQueue(&Q);
    GenerateKnowledgeTreeBFS(Height, PC);

    PrintQueue(&Q);
  }
}
#endif
